package me.hgj.jetpackmvvm.ledun.viewmodel.state

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import cn.com.heaton.blelibrary.ble.model.BleDevice
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel


class MainViewModel : BaseViewModel() {
    private val _sharedData = MutableLiveData<MutableList<BleDevice>>()
    val sharedData: LiveData<MutableList<BleDevice>>
        get() = _sharedData

    // 提供一个set方法来更新数据
    fun setSharedData(newData: MutableList<BleDevice>) {
        _sharedData.value = newData
    }

    // 提供一个get方法来获取数据的当前值
    fun getSharedData(): MutableList<BleDevice>? {
        return _sharedData.value
    }
    // 如果需要添加单个设备到列表
    fun addDevice(device: BleDevice) {
        val currentList = _sharedData.value ?: mutableListOf()
        currentList.add(device)
        _sharedData.value = currentList
    }

    // 如果需要从列表中移除设备
    fun removeDevice(device: BleDevice) {
        _sharedData.value?.let {
            it.remove(device)
            _sharedData.value = it
        }
    }



}